package com.itdct.mto.core.manager;

import com.itdct.mto.core.context.ColumnContext;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;

import java.sql.ResultSet;

import lombok.extern.slf4j.Slf4j;

/**
 * @author Zhouwx
 * @date 2025/7/25 14:52:30
 * @version 1.0
 * @description
 */
@ConditionalOnProperty(name = "mto.database-mode", havingValue = "PW")
@Component
@Slf4j
public class PanweiDataTransferManager extends BDataTransferManager {
    @Override
    protected void appendInsertLineSql(StringBuilder insertBuilder, ColumnContext columnContext) throws Exception {
        ResultSet rs = columnContext.getRs();
        String columnValue = columnContext.getColumnValue();

        // INFO: Zhouwx: 2025/7/25 磐维不支持bit类型，因此不需要加b‘0’
        if (rs.wasNull()) {
            // INFO: Zhouwx: 2025/7/2 值为NULL，那就直接写入NULL
            insertBuilder.append("NULL");
        } else {
            if (columnValue.isEmpty()) {
                insertBuilder.append("''");
            } else {
                // INFO: Zhouwx: 2025/7/2 字符串类型都需要转义，防止出现SQL报错
                if (mtoConfig.isMysqlToMysql()) {
                    columnValue = escapeForMySQL(columnValue);
                } else {
                    columnValue = escapeForOpenGauss(columnValue);
                }
                insertBuilder.append("'").append(columnValue).append("'");
            }
        }
    }
}
